- use xlisten/xsocket some more. Saves .25 kB
This commit is contained in:
parent
359d7ca0e7
commit
28fbd69bf8
@ -199,21 +199,21 @@ static int listen_socket(char *iface_addr, int listen_port)
|
|||||||
{
|
{
|
||||||
struct sockaddr_in a;
|
struct sockaddr_in a;
|
||||||
char msg[100];
|
char msg[100];
|
||||||
int s;
|
int sck;
|
||||||
s = xsocket(PF_INET, SOCK_DGRAM, 0);
|
sck = xsocket(PF_INET, SOCK_DGRAM, 0);
|
||||||
if (setsockopt_reuseaddr(s) < 0)
|
if (setsockopt_reuseaddr(sck) < 0)
|
||||||
bb_perror_msg_and_die("setsockopt() failed");
|
bb_perror_msg_and_die("setsockopt() failed");
|
||||||
memset(&a, 0, sizeof(a));
|
memset(&a, 0, sizeof(a));
|
||||||
a.sin_port = htons(listen_port);
|
a.sin_port = htons(listen_port);
|
||||||
a.sin_family = AF_INET;
|
a.sin_family = AF_INET;
|
||||||
if (!inet_aton(iface_addr, &a.sin_addr))
|
if (!inet_aton(iface_addr, &a.sin_addr))
|
||||||
bb_perror_msg_and_die("bad iface address");
|
bb_perror_msg_and_die("bad iface address");
|
||||||
xbind(s, (struct sockaddr *)&a, sizeof(a));
|
xbind(sck, (struct sockaddr *)&a, sizeof(a));
|
||||||
xlisten(s, 50);
|
xlisten(sck, 50);
|
||||||
sprintf(msg, "accepting UDP packets on addr:port %s:%d\n",
|
sprintf(msg, "accepting UDP packets on addr:port %s:%d\n",
|
||||||
iface_addr, (int)listen_port);
|
iface_addr, (int)listen_port);
|
||||||
log_message(LOG_FILE, msg);
|
log_message(LOG_FILE, msg);
|
||||||
return s;
|
return sck;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -412,8 +412,6 @@ int dnsd_main(int argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
udps = listen_socket(listen_interface, port);
|
udps = listen_socket(listen_interface, port);
|
||||||
if (udps < 0)
|
|
||||||
exit(1);
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
fd_set fdset;
|
fd_set fdset;
|
||||||
|
@ -40,20 +40,12 @@ int raw_socket(int ifindex)
|
|||||||
struct sockaddr_ll sock;
|
struct sockaddr_ll sock;
|
||||||
|
|
||||||
DEBUG("Opening raw socket on ifindex %d", ifindex);
|
DEBUG("Opening raw socket on ifindex %d", ifindex);
|
||||||
fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
|
fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
|
||||||
if (fd < 0) {
|
|
||||||
bb_perror_msg("socket");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
sock.sll_family = AF_PACKET;
|
sock.sll_family = AF_PACKET;
|
||||||
sock.sll_protocol = htons(ETH_P_IP);
|
sock.sll_protocol = htons(ETH_P_IP);
|
||||||
sock.sll_ifindex = ifindex;
|
sock.sll_ifindex = ifindex;
|
||||||
if (bind(fd, (struct sockaddr *) &sock, sizeof(sock)) < 0) {
|
xbind(fd, (struct sockaddr *) &sock, sizeof(sock));
|
||||||
bb_perror_msg("bind");
|
|
||||||
close(fd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
@ -278,10 +278,6 @@ int udhcpc_main(int argc, char *argv[])
|
|||||||
fd = listen_socket(INADDR_ANY, CLIENT_PORT, client_config.interface);
|
fd = listen_socket(INADDR_ANY, CLIENT_PORT, client_config.interface);
|
||||||
else
|
else
|
||||||
fd = raw_socket(client_config.ifindex);
|
fd = raw_socket(client_config.ifindex);
|
||||||
if (fd < 0) {
|
|
||||||
bb_perror_msg("FATAL: cannot listen on socket");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
max_fd = udhcp_sp_fd_set(&rfds, fd);
|
max_fd = udhcp_sp_fd_set(&rfds, fd);
|
||||||
|
|
||||||
|
@ -70,10 +70,6 @@ int udhcpd_main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (server_socket < 0) {
|
if (server_socket < 0) {
|
||||||
server_socket = listen_socket(INADDR_ANY, SERVER_PORT, server_config.interface);
|
server_socket = listen_socket(INADDR_ANY, SERVER_PORT, server_config.interface);
|
||||||
if (server_socket < 0) {
|
|
||||||
bb_perror_msg("FATAL: cannot create server socket");
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
max_sock = udhcp_sp_fd_set(&rfds, server_socket);
|
max_sock = udhcp_sp_fd_set(&rfds, server_socket);
|
||||||
|
@ -169,7 +169,6 @@ static int init_sockets(char **client, int num_clients,
|
|||||||
|
|
||||||
/* talk to real server on bootps */
|
/* talk to real server on bootps */
|
||||||
fds[0] = listen_socket(htonl(INADDR_ANY), 67, server);
|
fds[0] = listen_socket(htonl(INADDR_ANY), 67, server);
|
||||||
if (fds[0] < 0) return -1;
|
|
||||||
*max_socket = fds[0];
|
*max_socket = fds[0];
|
||||||
|
|
||||||
/* array starts at 1 since server is 0 */
|
/* array starts at 1 since server is 0 */
|
||||||
@ -178,7 +177,6 @@ static int init_sockets(char **client, int num_clients,
|
|||||||
for (i=1; i < num_clients; i++) {
|
for (i=1; i < num_clients; i++) {
|
||||||
/* listen for clients on bootps */
|
/* listen for clients on bootps */
|
||||||
fds[i] = listen_socket(htonl(INADDR_ANY), 67, client[i-1]);
|
fds[i] = listen_socket(htonl(INADDR_ANY), 67, client[i-1]);
|
||||||
if (fds[i] < 0) return -1;
|
|
||||||
if (fds[i] > *max_socket) *max_socket = fds[i];
|
if (fds[i] > *max_socket) *max_socket = fds[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,8 +319,6 @@ int dhcprelay_main(int argc, char **argv)
|
|||||||
signal(SIGINT, dhcprelay_signal_handler);
|
signal(SIGINT, dhcprelay_signal_handler);
|
||||||
|
|
||||||
num_sockets = init_sockets(clients, num_sockets, argv[2], fds, &max_socket);
|
num_sockets = init_sockets(clients, num_sockets, argv[2], fds, &max_socket);
|
||||||
if (num_sockets == -1)
|
|
||||||
bb_perror_msg_and_die("init_sockets() failed");
|
|
||||||
|
|
||||||
if (read_interface(argv[2], NULL, &gw_ip, NULL) == -1)
|
if (read_interface(argv[2], NULL, &gw_ip, NULL) == -1)
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -95,11 +95,7 @@ int listen_socket(uint32_t ip, int port, char *inf)
|
|||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
|
|
||||||
DEBUG("Opening listen socket on 0x%08x:%d %s", ip, port, inf);
|
DEBUG("Opening listen socket on 0x%08x:%d %s", ip, port, inf);
|
||||||
fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
fd = xsocket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
if (fd < 0) {
|
|
||||||
bb_perror_msg("socket");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user