mirror of
https://git.busybox.net/udhcp
synced 2025-05-08 22:09:45 +08:00
raw sockets added/newline added
This commit is contained in:
parent
882a605c46
commit
dbbee68430
38
socket.c
38
socket.c
@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user