/********************************************************************/ /* */ /* RTVPCNAM : 遠隔PC名の取得 */ /* */ /* Office Quattro Co,.Ltd 2007/10/16 13:35:47 created */ /* */ /* このプログラムは AUTOWEB から呼び出されて */ /* NetBios によって遠隔のPCの名前を取得します。 */ /* */ /* CRTCMOD RTVPCNAM */ /* CRTPGM ASNET.COM/RTVPCNAM BNDSRVPGM(CVTMOD4) */ /* */ /********************************************************************/ #pragma comment(COPYRIGHT, "as400-net.com EnterpriseServer (C) CopyRight \ Office Quattro.Corp. 2007- All right reserved. Users Restricted \ Rights - Use, duplication or disclosure restricted by Office Quattro \ Corp. Licenced Materials-Property of Office Quattro.") #include #include #include #include #include #include #include #include #include #include #include /* triml */ #define TRUE 0 #define FALSE -1 typedef struct { int BYTESPRO; int BYTESAVL; char MSGID[7]; char RESRVD; char EXCPDATA[100]; } ERRSTRUCTURE; /* Define the error return structure */ ERRSTRUCTURE errcode;/* Error Code Structure for RCVMSG */ /* char addr[13] = "192.168.1.11"; */ char* remote_addr; int PORT = 137; /*************************************************************/ /* 内 部 使 用  関  数 */ /*************************************************************/ void GetParam(int argc, char *argv[]); void INZSR(void); void err_log(char* msg, int opt, char* function, int line); /*************************************************************/ /* IMPORT  関  数 */ /*************************************************************/ int toEBCDIC(char* ebcbuf, char* ascbuf, char table[10],char tbllib[10], int bSISO); /*************************************************************/ /* 外 部 呼 出 し  関  数 */ /*************************************************************/ /*************************************************************/ /* グ ロ ー バ ル 変 数 */ /*************************************************************/ /*------( 受取りパラメータ値 )----------*/ /********************************************************************/ /* m a i n --- main module of this pgm */ /* */ /* 1. PCNAME[10] */ /* */ /*------------------------------------------------------------------*/ int main(int argc, char *argv[]){ int i, sockfd, len, rc, addr_len; struct sockaddr_in iaddr; char buff[256]; char request[] = { 0xa2, 0x48, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x43, 0x4b, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x00, 0x00, 0x21, 0x00, 0x01}; int offset, rep, pi; /* 2007/10/14 */ char type, class, name[17], typestr[128]; /* 2007/10/14 */ char ebc_name[20]; GetParam(argc, argv); /*[ パラメータの取得 ]*/ INZSR(); /*[ 初期設定 ]*/ /*-------------------------------------------------------*/ /* socket : Get a socket descriptor */ /*-------------------------------------------------------*/ if((sockfd = socket(PF_INET, SOCK_DGRAM, 0 )) < 0){ perror("RTVPCNAM SOCKET"); getchar(); exit(0); } /*-----------------------------------------------------------*/ /* connect: connect to the server using a set of port number */ /*-----------------------------------------------------------*/ memset(&iaddr, 0x00, sizeof(struct sockaddr_in)); iaddr.sin_family = PF_INET; iaddr.sin_port = htons(PORT); /* PORT no set*/ iaddr.sin_addr.s_addr = inet_addr(remote_addr);/* IP の設定 20071015 */ rc = connect(sockfd, (struct sockaddr *)&iaddr, sizeof(iaddr)); if(rc < 0){ printf("%s %x-%x--", remote_addr,iaddr.sin_addr.s_addr,iaddr.sin_port); perror("RTVPCNAM CONNECT"); getchar(); exit(0); } /*-----------------------------------------------------------*/ /* send a message to the server using secure session */ /*-----------------------------------------------------------*/ len = sizeof(request); rc = send(sockfd, request, len, 0); if(rc != len){ if(rc < 0){ perror("SEND"); getchar(); exit(0); } else{ printf("SEND did not all data\n"); getchar(); exit(0); } } /*-----------------------------------------------------------*/ /* receive the message from the server using SOCKET */ /*-----------------------------------------------------------*/ memset(buff, 0, sizeof(buff)); len = sizeof(buff); rc = recv(sockfd, buff, len, 0); if(rc < 0){ perror("RTVPCNAM RECV"); getchar(); exit(0); } close(sockfd); /* 2007/10/14 NetBIOSプロパティ の出力 */ offset = 57; /* ここから プロパティ */ rep = buff[offset-1]; /* プロパティ 数を取得 */ for(pi=0; pi 0) ebc_name[len] = 0x00; while(strlen(ebc_name) < 10) strcat(ebc_name, " "); memcpy(argv[1], ebc_name, 10); /* 10 桁の PC 名を取得 */ break; /* テスト 印刷ここまで */ offset += 18; }/* プロパティ 数の ループ*/ exit(0); } /*************************************/ void GetParam(int argc, char *argv[]) /*************************************/ { char env[256]; } /****************/ void INZSR(void) /****************/ { errcode.BYTESPRO = errcode.BYTESAVL = 0; remote_addr = getenv("REMOTE_ADDR"); } /********************************************************/ void err_log(char* msg, int opt, char* err_at, int line) /********************************************************/ { fprintf(stderr, "%s\n", msg); fprintf(stderr, " ->ERR AT = %s, LINE = %d\n", err_at, line); if(opt == TRUE) fprintf(stderr, "%s\n", strerror(errno)); }