2006-03-05 02:29:34 +01:00
|
|
|
#ifndef _SOCKET_H_
|
|
|
|
#define _SOCKET_H_
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#include "netpkt.h"
|
|
|
|
|
2006-04-15 19:55:07 +02:00
|
|
|
class Socket : private ListEntry<Socket> {
|
2006-03-05 02:29:34 +01:00
|
|
|
public:
|
|
|
|
Socket();
|
|
|
|
~Socket();
|
|
|
|
|
|
|
|
static Socket* createSocket(struct sockaddr_in* addr);
|
|
|
|
static Socket* createSocket(const char* name, int port);
|
|
|
|
|
|
|
|
int show(char* buf, int size);
|
|
|
|
|
|
|
|
int sendto(NetPkt* pkt, struct sockaddr_in* dst = NULL);
|
|
|
|
NetPkt* recv();
|
|
|
|
|
|
|
|
int getFD();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Socket(const Socket& s);
|
|
|
|
Socket& operator=(const Socket& s);
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool checkDeviceFlags(const char* name);
|
|
|
|
bool bindToDevice(const char* name);
|
|
|
|
bool bindToAddress(struct sockaddr_in* addr);
|
|
|
|
bool setBroadcast(int flag);
|
|
|
|
|
|
|
|
int getRecvSize();
|
|
|
|
|
|
|
|
int fd;
|
|
|
|
char devname[IFNAMSIZ];
|
|
|
|
struct sockaddr_in addr;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _SOCKET_H_
|