{
struct sockaddr_in a;
char msg[100];
- int s;
- s = xsocket(PF_INET, SOCK_DGRAM, 0);
- if (setsockopt_reuseaddr(s) < 0)
+ int sck;
+ sck = xsocket(PF_INET, SOCK_DGRAM, 0);
+ if (setsockopt_reuseaddr(sck) < 0)
bb_perror_msg_and_die("setsockopt() failed");
memset(&a, 0, sizeof(a));
a.sin_port = htons(listen_port);
a.sin_family = AF_INET;
if (!inet_aton(iface_addr, &a.sin_addr))
bb_perror_msg_and_die("bad iface address");
- xbind(s, (struct sockaddr *)&a, sizeof(a));
- xlisten(s, 50);
+ xbind(sck, (struct sockaddr *)&a, sizeof(a));
+ xlisten(sck, 50);
sprintf(msg, "accepting UDP packets on addr:port %s:%d\n",
iface_addr, (int)listen_port);
log_message(LOG_FILE, msg);
- return s;
+ return sck;
}
/*
#endif
udps = listen_socket(listen_interface, port);
- if (udps < 0)
- exit(1);
while (1) {
fd_set fdset;
struct sockaddr_ll sock;
DEBUG("Opening raw socket on ifindex %d", ifindex);
- fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
- if (fd < 0) {
- bb_perror_msg("socket");
- return -1;
- }
+ fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
sock.sll_family = AF_PACKET;
sock.sll_protocol = htons(ETH_P_IP);
sock.sll_ifindex = ifindex;
- if (bind(fd, (struct sockaddr *) &sock, sizeof(sock)) < 0) {
- bb_perror_msg("bind");
- close(fd);
- return -1;
- }
+ xbind(fd, (struct sockaddr *) &sock, sizeof(sock));
return fd;
}
fd = listen_socket(INADDR_ANY, CLIENT_PORT, client_config.interface);
else
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);
if (server_socket < 0) {
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);
/* talk to real server on bootps */
fds[0] = listen_socket(htonl(INADDR_ANY), 67, server);
- if (fds[0] < 0) return -1;
*max_socket = fds[0];
/* array starts at 1 since server is 0 */
for (i=1; i < num_clients; i++) {
/* listen for clients on bootps */
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];
}
signal(SIGINT, dhcprelay_signal_handler);
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)
return 1;
struct sockaddr_in addr;
DEBUG("Opening listen socket on 0x%08x:%d %s", ip, port, inf);
- fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
- if (fd < 0) {
- bb_perror_msg("socket");
- return -1;
- }
+ fd = xsocket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;