/* request config from an MS SQL server instance. * * The default port is 1434, If "Hide server" [sic] checkbox * has been ticked the port changes to 2433 which can * be forced using the net!ipaddr!2433 address symantics */ #include #include #include #include static void ding(void *u, char *msg) { USED(u); if(strstr(msg, "alarm")) noted(NCONT); noted(NDFLT); } static void usage(void) { fprint(2, "usage: %s host\n", argv0); exits("usage"); } void main(int argc, char **argv) { int fd, n; char *p, *port, *addr, buf[1024]; if (argc != 2) usage(); addr = netmkaddr(argv[1], "udp", "1434"); if((port = strrchr(addr, '!')) == nil) sysfatal("%s - cannot find port in network address\n", addr); port++; notify(ding); if((fd = dial(addr, port, 0, 0)) < 0) sysfatal("can't dial - %s : %r", argv[1]); *buf = 2; if (write(fd, buf, 1) != 1) sysfatal("can't write: %r"); memset(buf, 0, sizeof(buf)); alarm(300); if ((n = read(fd, buf, sizeof(buf))) < 2) sysfatal("timeout"); alarm(0); buf[sizeof(buf)-1] = 0; if(n < 4) exits(nil); p = buf+3; if((p = strrchr(p, ';')) != nil) *p = 0; p = buf+3; while(p-buf < n-4){ if((p = strchr(p, ';')) != nil) *p = '='; if((p = strchr(p, ';')) != nil) *p = '\n'; } print("%s", buf+3); exits(nil); }