1 #include <netinet/in.h>
10 static int open_socket_out(char *host, int port)
12 struct sockaddr_in sock_out;
16 res = socket(PF_INET, SOCK_STREAM, 0);
18 hp = gethostbyname(host);
20 fprintf(stderr,"unknown host: %s\n", host);
24 memcpy(&sock_out.sin_addr, hp->h_addr, hp->h_length);
25 sock_out.sin_port = htons(port);
26 sock_out.sin_family = PF_INET;
28 if (connect(res,(struct sockaddr *)&sock_out,sizeof(sock_out))) {
29 fprintf(stderr, "failed to connect to %s - %s\n", host, strerror(errno));
36 int main(int argc, char *argv[])
44 printf("usage: issamba <host>\n");
52 sock = open_socket_out(host, port);
54 if (write(sock, buf, 4) != 4) {
55 fprintf(stderr,"Failed to send request\n");
60 if (read(sock, buf, 4) != 4) {
61 fprintf(stderr,"Failed to recv request\n");
66 printf("%s is a Samba server\n", host);
68 printf("%s is not a Samba server (0x%02x)\n", host, buf[0]);