raw sockets added/newline added

This commit is contained in:
Russ Dill 2001-08-11 00:39:46 +00:00
parent 882a605c46
commit dbbee68430
2 changed files with 38 additions and 3 deletions

View File

@ -28,6 +28,19 @@
#include <unistd.h>
#include <string.h>
#include <net/if.h>
#include <errno.h>
#include <features.h>
#if __GLIBC__ >=2 && __GLIBC_MINOR >= 1
#include <netpacket/packet.h>
#include <net/ethernet.h>
#else
#include <asm/types.h>
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#endif
#include "debug.h"
int listen_socket(unsigned int ip, int port, char *inf)
{
@ -36,9 +49,11 @@ int listen_socket(unsigned int ip, int port, char *inf)
struct sockaddr_in addr;
int n = 1;
if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
DEBUG(LOG_ERR, "socket call failed: %s", sys_errlist[errno]);
return -1;
}
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
@ -68,4 +83,23 @@ int listen_socket(unsigned int ip, int port, char *inf)
}
int raw_socket(char *inf)
{
int fd;
struct ifreq interface;
if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) {
DEBUG(LOG_ERR, "socket call failed: %s", sys_errlist[errno]);
return -1;
}
strncpy(interface.ifr_ifrn.ifrn_name, inf, IFNAMSIZ);
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,(char *)&interface, sizeof(interface)) < 0) {
close(fd);
return -1;
}
return fd;
}

View File

@ -3,5 +3,6 @@
#define _SOCKET_H
int listen_socket(unsigned int ip, int port, char *inf);
int raw_socket(char *inf);
#endif
#endif