13 #include <sys/socket.h>
14 #include <netinet/in.h>
15 #include <netinet/tcp.h>
22 p9dial(char *addr, char *dummy1, char *dummy2, int *dummy3)
29 struct sockaddr_in sa;
30 struct sockaddr_un su;
33 if(dummy1 || dummy2 || dummy3){
34 werrstr("cannot handle extra arguments in dial");
42 if(p9dialparse(buf, &net, &unix, &host, &port) < 0){
47 if(strcmp(net, "tcp") == 0)
49 else if(strcmp(net, "udp") == 0)
51 else if(strcmp(net, "unix") == 0)
54 werrstr("can only handle tcp, udp, and unix: not %s", net);
60 memset(&sa, 0, sizeof sa);
61 memmove(&sa.sin_addr, &host, 4);
62 sa.sin_family = AF_INET;
63 sa.sin_port = htons(port);
64 if((s = socket(AF_INET, proto, 0)) < 0)
66 if(connect(s, (struct sockaddr*)&sa, sizeof sa) < 0){
70 if(proto == SOCK_STREAM){
72 setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char*)&one, sizeof one);
77 memset(&su, 0, sizeof su);
78 su.sun_family = AF_UNIX;
79 if(strlen(unix)+1 > sizeof su.sun_path){
80 werrstr("unix socket name too long");
84 strcpy(su.sun_path, unix);
86 if((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
88 if(connect(s, (struct sockaddr*)&su, sizeof su) < 0){