13 #include <sys/socket.h>
14 #include <netinet/in.h>
15 #include <netinet/tcp.h>
20 extern int _p9dialparse(char*, char**, char**, u32int*, int*);
24 p9dial(char *addr, char *dummy1, char *dummy2, int *dummy3)
31 struct sockaddr_in sa;
32 struct sockaddr_un su;
35 if(dummy1 || dummy2 || dummy3){
36 werrstr("cannot handle extra arguments in dial");
44 if(_p9dialparse(buf, &net, &unix, &host, &port) < 0){
49 if(strcmp(net, "tcp") == 0)
51 else if(strcmp(net, "udp") == 0)
53 else if(strcmp(net, "unix") == 0)
56 werrstr("can only handle tcp, udp, and unix: not %s", net);
62 memset(&sa, 0, sizeof sa);
63 memmove(&sa.sin_addr, &host, 4);
64 sa.sin_family = AF_INET;
65 sa.sin_port = htons(port);
66 if((s = socket(AF_INET, proto, 0)) < 0)
68 if(connect(s, (struct sockaddr*)&sa, sizeof sa) < 0){
72 if(proto == SOCK_STREAM){
74 setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char*)&one, sizeof one);
79 memset(&su, 0, sizeof su);
80 su.sun_family = AF_UNIX;
81 if(strlen(unix)+1 > sizeof su.sun_path){
82 werrstr("unix socket name too long");
86 strcpy(su.sun_path, unix);
88 if((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
90 if(connect(s, (struct sockaddr*)&su, sizeof su) < 0){