From owner-freebsd-questions Wed Jan 22 8:58:27 2003 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AEFC737B401 for ; Wed, 22 Jan 2003 08:58:25 -0800 (PST) Received: from undead.dnn.ru (dnn.ru [212.158.164.253]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4EAEE43F13 for ; Wed, 22 Jan 2003 08:58:23 -0800 (PST) (envelope-from alex@dynaweb.ru) Received: from dynaweb.ru (dynaweb.dnn.ru [212.158.164.112]) by undead.dnn.ru (8.9.3/8.9.3) with ESMTP id UAA25532 for ; Wed, 22 Jan 2003 20:00:53 +0300 (MSK) (envelope-from alex@dynaweb.ru) Message-ID: <3E2ECF93.1090508@dynaweb.ru> Date: Wed, 22 Jan 2003 20:06:27 +0300 From: Alex Reply-To: alex@dynaweb.ru User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0.1) Gecko/20020823 Netscape/7.0 X-Accept-Language: en-us, en MIME-Version: 1.0 To: freebsd-questions@FreeBSD.org Subject: problems with adding ipfw rules via raw sockets Content-Type: text/plain; charset=windows-1251; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hi ppl! I need to use direct access ti ipfw rules via raw sockets instead of some scripts using ipfw utility. I looked into ipfw sources and made a simple program to test if I could add a simple rule this way. Just rewrote pieces of original code intomy program w/out any serious change. But setsockopt() always return EINVAL and string msg "Invalid argument". And no details. Hence I'm in a fix. Icannot get what's wrong indeed. Here I place my code (short anough). Any advice would be appritiated. Maybe some links to some docs - I failed to find anything but a very short info in manpages. #include #include #include #include #include #include #include #include #include int test(void) { int sock,res,sz; struct ip_fw rule; sock = socket(AF_INET,SOCK_RAW,IPPROTO_RAW); if (sock==-1) {printf("\n\nsoket() failed with \"%s\"\n\n",strerror(errno)); return -1;}; printf("\nsock = %i\n",sock); memset(&rule,0,sizeof(struct ip_fw)); rule.fw_number = 700; rule.fw_flg = IP_FW_F_DENY; rule.fw_src.s_addr = inet_addr("195.48.121.34"); rule.fw_smsk.s_addr = inet_addr("255.255.255.255"); rule.fw_dst.s_addr = inet_addr("127.0.0.0"); rule.fw_dmsk.s_addr = inet_addr("255.0.0.0"); rule.fw_prot = IPPROTO_IP; sz = sizeof(struct ip_fw); res = setsockopt(sock,IPPROTO_IP,IP_FW_ADD,&rule,&sz); if (res==-1) {printf("\n\nsetsockopt() failed with \"%s\"\n\n",strerror(errno)); return -1;}; return 0; }; int main(void) { test(); return 0; }; Alexander Komratov To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message