<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: program in c - error in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/program-in-c-error/m-p/4790122#M641228</link>
    <description>&lt;!--!*#--&gt;&amp;gt; Do you mean to do something like this&lt;BR /&gt;&amp;gt; [...]?&lt;BR /&gt;&lt;BR /&gt;I was guessing more like this:&lt;BR /&gt;&lt;BR /&gt;alp $ type portcheck.c&lt;BR /&gt;#include &lt;SYS&gt;&lt;BR /&gt;#include &lt;SYS&gt;&lt;BR /&gt;#include &lt;SYS&gt;&lt;BR /&gt;&lt;BR /&gt;#include &lt;ARPA&gt;&lt;BR /&gt;&lt;BR /&gt;#include &lt;NETINET&gt;&lt;BR /&gt;&lt;BR /&gt;#include &lt;ERRNO.H&gt;&lt;BR /&gt;#include &lt;FCNTL.H&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;NETDB.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;#include &lt;STRING.H&gt;&lt;BR /&gt;#include &lt;UNISTD.H&gt;&lt;BR /&gt;&lt;BR /&gt;int main(int argc, char **argv)&lt;BR /&gt;{&lt;BR /&gt;    u_short port; /* user specified port number */&lt;BR /&gt;    struct sockaddr_in address; /* address structures */&lt;BR /&gt;    struct hostent *host_info; /* host info structure */&lt;BR /&gt;    short int sock = -1; /* the socket descriptor */&lt;BR /&gt;    int sts = 0;&lt;BR /&gt;&lt;BR /&gt;    if (argc != 3)&lt;BR /&gt;        exit( EINVAL);&lt;BR /&gt;&lt;BR /&gt;    port = atoi(argv[1]);&lt;BR /&gt;    bzero((char *)&amp;amp;address, sizeof(address)); /* init addr struct */&lt;BR /&gt;    address.sin_addr.s_addr = inet_addr(argv[2]); /* assign the address */&lt;BR /&gt;    address.sin_port = htons(port); /* translate int2port num */&lt;BR /&gt;    address.sin_family = AF_INET; /* Address family. */&lt;BR /&gt;&lt;BR /&gt;    sock = socket( address.sin_family, SOCK_STREAM, 0);&lt;BR /&gt;    if (sock &amp;lt; 0)&lt;BR /&gt;    {&lt;BR /&gt;        fprintf( stderr, " socket(): %s\n", strerror( errno));&lt;BR /&gt;        sts = errno;&lt;BR /&gt;    }&lt;BR /&gt;    else&lt;BR /&gt;    {&lt;BR /&gt;        if (connect( sock, (struct sockaddr *)&amp;amp;address, sizeof(address)) == 0)&lt;BR /&gt;        {&lt;BR /&gt;            fprintf( stderr, "Port %d is open on %s.\n", port, argv[2]);&lt;BR /&gt;        }&lt;BR /&gt;        else&lt;BR /&gt;        {&lt;BR /&gt;            fprintf( stderr, " connect(): %s\n", strerror( errno));&lt;BR /&gt;            sts = errno;&lt;BR /&gt;        }&lt;BR /&gt;        close(sock);&lt;BR /&gt;    }&lt;BR /&gt;    exit( sts);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;alp $ cc portcheck /define = (_POSIX_EXIT)&lt;BR /&gt;alp $ link portcheck&lt;BR /&gt;alp $ exec portcheck 80 10.0.0.9&lt;BR /&gt;Port 80 is open on 10.0.0.9.&lt;BR /&gt;alp $ exec portcheck 81 10.0.0.9&lt;BR /&gt; connect(): connection refused&lt;BR /&gt;&lt;BR /&gt;I don't write enough socket code to know&lt;BR /&gt;much, but I can find plenty of good code from&lt;BR /&gt;which to steal some working bits.&lt;/UNISTD.H&gt;&lt;/STRING.H&gt;&lt;/STDLIB.H&gt;&lt;/NETDB.H&gt;&lt;/STDIO.H&gt;&lt;/FCNTL.H&gt;&lt;/ERRNO.H&gt;&lt;/NETINET&gt;&lt;/ARPA&gt;&lt;/SYS&gt;&lt;/SYS&gt;&lt;/SYS&gt;</description>
    <pubDate>Sat, 21 May 2011 23:02:23 GMT</pubDate>
    <dc:creator>Steven Schweda</dc:creator>
    <dc:date>2011-05-21T23:02:23Z</dc:date>
    <item>
      <title>program in c - error</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/program-in-c-error/m-p/4790116#M641222</link>
      <description>I'm trying to compile the below program but there is an error:&lt;BR /&gt;&lt;BR /&gt;gcc -o portcheck portcheck.c &lt;BR /&gt;portcheck.c: In function ‘main’:&lt;BR /&gt;portcheck.c:26: error: incompatible types when assigning to type ‘char[1023]’ from type ‘char *’&lt;BR /&gt;&lt;BR /&gt;Please help&lt;BR /&gt;==============================================&lt;BR /&gt;#include &lt;SYS&gt;&lt;BR /&gt;#include &lt;SYS&gt;&lt;BR /&gt;#include &lt;SYS&gt;&lt;BR /&gt;&lt;BR /&gt;#include &lt;ARPA&gt;&lt;BR /&gt;&lt;BR /&gt;#include &lt;NETINET&gt;&lt;BR /&gt;&lt;BR /&gt;#include &lt;ERRNO.H&gt;&lt;BR /&gt;#include &lt;FCNTL.H&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;NETDB.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;#include &lt;STRING.H&gt;&lt;BR /&gt;#include &lt;UNISTD.H&gt;&lt;BR /&gt;&lt;BR /&gt;int main(int argc, char **argv)&lt;BR /&gt;{&lt;BR /&gt;    u_short port;               /* user specified port number */&lt;BR /&gt;    char addr[1023];            /* the address */&lt;BR /&gt;    struct sockaddr_in address; /* address structures */&lt;BR /&gt;    struct hostent *host_info;  /* host info structure */&lt;BR /&gt;    short int sock = -1;        /* the socket descriptor */&lt;BR /&gt;&lt;BR /&gt;    port = atoi(argv[1]);&lt;BR /&gt;    addr = strncpy(addr, argv[2], 1023);&lt;BR /&gt;    bzero((char *)&amp;amp;address, sizeof(address)); /* init addr struct */&lt;BR /&gt;    address.sin_addr.s_addr = inet_addr(addr); /* assign the address */&lt;BR /&gt;    address.sin_port = htons(port);               /* translate int2port num */&lt;BR /&gt;&lt;BR /&gt;        /*&lt;BR /&gt;         * Three simple steps:&lt;BR /&gt;         *     1. Open the master socket locally&lt;BR /&gt;         *     2. Try to connect to hostbyport, if it works&lt;BR /&gt;     *        print the successful message.&lt;BR /&gt;         *     3. If no route then complain with vulgarity &lt;BR /&gt;     *        (it is just a rapid prototype after all)&lt;BR /&gt;         * Otherwise do nothing.&lt;BR /&gt;     */&lt;BR /&gt;    sock = socket(AF_INET, SOCK_STREAM, 0);&lt;BR /&gt;    if(connect(sock,(struct sockaddr *)&amp;amp;address,sizeof(address)) == 0)&lt;BR /&gt;        printf("%i is open on %s\n", port, argv[2]);&lt;BR /&gt;&lt;BR /&gt;    if (errno == 113) fprintf(stderr, "F*^k - no route to host\n");&lt;BR /&gt;&lt;BR /&gt;    close(sock);&lt;BR /&gt;&lt;BR /&gt;    return 0;&lt;BR /&gt;}&lt;BR /&gt;&lt;/UNISTD.H&gt;&lt;/STRING.H&gt;&lt;/STDLIB.H&gt;&lt;/NETDB.H&gt;&lt;/STDIO.H&gt;&lt;/FCNTL.H&gt;&lt;/ERRNO.H&gt;&lt;/NETINET&gt;&lt;/ARPA&gt;&lt;/SYS&gt;&lt;/SYS&gt;&lt;/SYS&gt;</description>
      <pubDate>Fri, 20 May 2011 04:55:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/program-in-c-error/m-p/4790116#M641222</guid>
      <dc:creator>Piotr Kirklewski</dc:creator>
      <dc:date>2011-05-20T04:55:26Z</dc:date>
    </item>
    <item>
      <title>Re: program in c - error</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/program-in-c-error/m-p/4790117#M641223</link>
      <description>In the line 26 you have addr as input as ouput:&lt;BR /&gt;&lt;BR /&gt;addr = strncpy(addr, argv[2], 1023);&lt;BR /&gt;&lt;BR /&gt;It is not a proper L value valid for output as provided.&lt;BR /&gt;Just drop it and use only:&lt;BR /&gt;&lt;BR /&gt;strncpy(addr, argv[2], 1023);&lt;BR /&gt;&lt;BR /&gt;If you need the output then you need something like:&lt;BR /&gt;&lt;BR /&gt;char *p;&lt;BR /&gt;:&lt;BR /&gt;p = strncpy(addr, argv[2], 1023);&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein&lt;BR /&gt;</description>
      <pubDate>Fri, 20 May 2011 05:12:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/program-in-c-error/m-p/4790117#M641223</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2011-05-20T05:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: program in c - error</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/program-in-c-error/m-p/4790118#M641224</link>
      <description>Hmm, 5/10. Did the reply not address the problem for which you asked for help?&lt;BR /&gt;Is there an other problem? Do explain.&lt;BR /&gt;Or just fat fingered the assignment? Just close.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Hein&lt;BR /&gt;</description>
      <pubDate>Sat, 21 May 2011 17:43:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/program-in-c-error/m-p/4790118#M641224</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2011-05-21T17:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: program in c - error</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/program-in-c-error/m-p/4790119#M641225</link>
      <description>Thanks&lt;BR /&gt;Now it compiles fine but it always says the host is active even if there is no such IP in the network.&lt;BR /&gt;What would be the reason for that ?&lt;BR /&gt;Reagrds&lt;BR /&gt;Peter</description>
      <pubDate>Sat, 21 May 2011 18:08:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/program-in-c-error/m-p/4790119#M641225</guid>
      <dc:creator>Piotr Kirklewski</dc:creator>
      <dc:date>2011-05-21T18:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: program in c - error</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/program-in-c-error/m-p/4790120#M641226</link>
      <description>&lt;!--!*#--&gt;&amp;gt; What would be the reason for that ?&lt;BR /&gt;&lt;BR /&gt;Uh, bad code?&lt;BR /&gt;&lt;BR /&gt;&amp;gt; sock = socket(AF_INET, SOCK_STREAM, 0);&lt;BR /&gt;&lt;BR /&gt;Did that work?  How would you know?&lt;BR /&gt;&lt;BR /&gt;&amp;gt; if (errno == 113) fprintf(stderr, "F*^k - no route to host\n");&lt;BR /&gt;&lt;BR /&gt;How does that help you for any other value of&lt;BR /&gt;errno?&lt;BR /&gt;&lt;BR /&gt;      man strerror&lt;BR /&gt;&lt;BR /&gt;&amp;gt; return 0;&lt;BR /&gt;&lt;BR /&gt;Always?  How informative is that?</description>
      <pubDate>Sat, 21 May 2011 20:03:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/program-in-c-error/m-p/4790120#M641226</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2011-05-21T20:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: program in c - error</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/program-in-c-error/m-p/4790121#M641227</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Do you mean to do something like this (replace the body of your code with this)?&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;sock = socket(AF_INET, SOCK_STREAM, 0);&lt;BR /&gt;if (bind(sock,(struct sockaddr *)&amp;amp;address,sizeof(address)) == -1) {&lt;BR /&gt;    perror("bind");&lt;BR /&gt;    exit(1);&lt;BR /&gt;}&lt;BR /&gt;if (connect(sock,(struct sockaddr *)&amp;amp;address,sizeof(address)) == -1) {&lt;BR /&gt;    perror("connect");&lt;BR /&gt;    exit(1);&lt;BR /&gt;}&lt;BR /&gt;printf("%i is open on %s\n", port, argv[2]);&lt;BR /&gt;close(sock);&lt;BR /&gt;exit(0);&lt;BR /&gt;} &lt;BR /&gt;&lt;BR /&gt;Now, if I compile and run this like:&lt;BR /&gt;&lt;BR /&gt;# ./a.out 22 127.0.0.1&lt;BR /&gt;bind: Address already in use&lt;BR /&gt;# ./a.out 123 127.0.0.1&lt;BR /&gt;123 is open on 127.0.0.1&lt;BR /&gt;&lt;BR /&gt;Better?&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sat, 21 May 2011 21:20:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/program-in-c-error/m-p/4790121#M641227</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-05-21T21:20:54Z</dc:date>
    </item>
    <item>
      <title>Re: program in c - error</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/program-in-c-error/m-p/4790122#M641228</link>
      <description>&lt;!--!*#--&gt;&amp;gt; Do you mean to do something like this&lt;BR /&gt;&amp;gt; [...]?&lt;BR /&gt;&lt;BR /&gt;I was guessing more like this:&lt;BR /&gt;&lt;BR /&gt;alp $ type portcheck.c&lt;BR /&gt;#include &lt;SYS&gt;&lt;BR /&gt;#include &lt;SYS&gt;&lt;BR /&gt;#include &lt;SYS&gt;&lt;BR /&gt;&lt;BR /&gt;#include &lt;ARPA&gt;&lt;BR /&gt;&lt;BR /&gt;#include &lt;NETINET&gt;&lt;BR /&gt;&lt;BR /&gt;#include &lt;ERRNO.H&gt;&lt;BR /&gt;#include &lt;FCNTL.H&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;NETDB.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;#include &lt;STRING.H&gt;&lt;BR /&gt;#include &lt;UNISTD.H&gt;&lt;BR /&gt;&lt;BR /&gt;int main(int argc, char **argv)&lt;BR /&gt;{&lt;BR /&gt;    u_short port; /* user specified port number */&lt;BR /&gt;    struct sockaddr_in address; /* address structures */&lt;BR /&gt;    struct hostent *host_info; /* host info structure */&lt;BR /&gt;    short int sock = -1; /* the socket descriptor */&lt;BR /&gt;    int sts = 0;&lt;BR /&gt;&lt;BR /&gt;    if (argc != 3)&lt;BR /&gt;        exit( EINVAL);&lt;BR /&gt;&lt;BR /&gt;    port = atoi(argv[1]);&lt;BR /&gt;    bzero((char *)&amp;amp;address, sizeof(address)); /* init addr struct */&lt;BR /&gt;    address.sin_addr.s_addr = inet_addr(argv[2]); /* assign the address */&lt;BR /&gt;    address.sin_port = htons(port); /* translate int2port num */&lt;BR /&gt;    address.sin_family = AF_INET; /* Address family. */&lt;BR /&gt;&lt;BR /&gt;    sock = socket( address.sin_family, SOCK_STREAM, 0);&lt;BR /&gt;    if (sock &amp;lt; 0)&lt;BR /&gt;    {&lt;BR /&gt;        fprintf( stderr, " socket(): %s\n", strerror( errno));&lt;BR /&gt;        sts = errno;&lt;BR /&gt;    }&lt;BR /&gt;    else&lt;BR /&gt;    {&lt;BR /&gt;        if (connect( sock, (struct sockaddr *)&amp;amp;address, sizeof(address)) == 0)&lt;BR /&gt;        {&lt;BR /&gt;            fprintf( stderr, "Port %d is open on %s.\n", port, argv[2]);&lt;BR /&gt;        }&lt;BR /&gt;        else&lt;BR /&gt;        {&lt;BR /&gt;            fprintf( stderr, " connect(): %s\n", strerror( errno));&lt;BR /&gt;            sts = errno;&lt;BR /&gt;        }&lt;BR /&gt;        close(sock);&lt;BR /&gt;    }&lt;BR /&gt;    exit( sts);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;alp $ cc portcheck /define = (_POSIX_EXIT)&lt;BR /&gt;alp $ link portcheck&lt;BR /&gt;alp $ exec portcheck 80 10.0.0.9&lt;BR /&gt;Port 80 is open on 10.0.0.9.&lt;BR /&gt;alp $ exec portcheck 81 10.0.0.9&lt;BR /&gt; connect(): connection refused&lt;BR /&gt;&lt;BR /&gt;I don't write enough socket code to know&lt;BR /&gt;much, but I can find plenty of good code from&lt;BR /&gt;which to steal some working bits.&lt;/UNISTD.H&gt;&lt;/STRING.H&gt;&lt;/STDLIB.H&gt;&lt;/NETDB.H&gt;&lt;/STDIO.H&gt;&lt;/FCNTL.H&gt;&lt;/ERRNO.H&gt;&lt;/NETINET&gt;&lt;/ARPA&gt;&lt;/SYS&gt;&lt;/SYS&gt;&lt;/SYS&gt;</description>
      <pubDate>Sat, 21 May 2011 23:02:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/program-in-c-error/m-p/4790122#M641228</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2011-05-21T23:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: program in c - error</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/program-in-c-error/m-p/4790123#M641229</link>
      <description>&lt;!--!*#--&gt;&amp;gt;  Hmm, 5/10. [...]&lt;BR /&gt;&lt;BR /&gt;Smug ingratitude from the helpless is what&lt;BR /&gt;makes Forum participation so satisfying for&lt;BR /&gt;me.</description>
      <pubDate>Sun, 22 May 2011 01:01:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/program-in-c-error/m-p/4790123#M641229</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2011-05-22T01:01:20Z</dc:date>
    </item>
  </channel>
</rss>

