ofile.c

来自「这是一个MINITGUI2。0的应用程序」· C语言 代码 · 共 62 行

C
62
字号
#include <ctype.h>#include <errno.h>#include <fcntl.h>#include <signal.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/ioctl.h>#include <sys/wait.h>#include <sys/stat.h>#include <unistd.h>char * file="/usr/local/etc/ipconfig";int getipport(char *relip,char *relport){	int fd;	int num;	int i = 1, j = 0;	char buf[26];	char ipbuf[20];	char portbuf[5];	char *ip;	char *port;	if((fd = open(file, O_RDONLY, 0)) < 0){		printf("can't open file\n");			//perror("open");			return 1;	}	else{		printf("\n\nopen the %s successful\n");	}		num = read(fd,buf,26);	if(num < 0){		printf("read err\n");		return 2;	}	printf("read ok the data is %s",buf);	while(buf[i]!='"'){				ipbuf[i-1] = buf[i];		i++;			}	ipbuf[i-1] = '\0';	printf("\nlbub = %s",ipbuf);	ip = ipbuf;	printf ("\nthe ip is %s\n",ip);	i = 0;	while(buf[i++] != '*') ;	for(j = 0;j<4;j++){		portbuf[j] = buf[i++];	}	portbuf[j] = '\0';	printf("\nportbuf = %s",portbuf);	port = portbuf;	printf("\nthe relport is %s\n",port);	relip = ip;	relport = port;	close(fd);	return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?