1 /* (c) Copyright Hewlett-Packard Development Company, L.P., 2007
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of version 2 the GNU General Public License as
5 * published by the Free Software Foundation.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <linux/net.h>
21 int main(int argc
, char **argv
)
25 struct sockaddr_in my_addr
;
26 socklen_t addrlen
= sizeof(my_addr
);
29 fprintf(stderr
, "Usage:\n%s <op> <arg>...\n", argv
[0]);
33 if (!strcmp(argv
[1], "bind")) {
35 fprintf(stderr
, "Usage:\n%s bind <port> <0|127>\n", argv
[0]);
39 memset(&my_addr
, 0, addrlen
);
40 my_addr
.sin_family
= AF_INET
;
41 my_addr
.sin_port
= htons(atoi(argv
[2]));
42 my_addr
.sin_addr
.s_addr
= atoi(argv
[3]);
44 sockfd
= socket(PF_INET
, SOCK_STREAM
, 0);
46 perror("do_socketcall: open socket");
51 /* use library routine for build's sake */
52 exitval
= bind(sockfd
, (struct sockaddr
*)&my_addr
, addrlen
);
55 fprintf(stderr
, "%s: unimplemented op: %s\n", argv
[0], argv
[1]);
60 printf("%d %d %d\n", result
, result
? errno
: exitval
, getpid());