pointers and sockets in gcc

pointers and sockets in gcc

Post by Chris Palm » Thu, 11 Aug 1994 05:33:57





>struct sockaddr_in sockaddr;

>When my client goes to connect, the call is like this:

>if ( connect ( s, &sockaddr, sizeof(sockaddr)) < 0 )
> ...

>When I compile it I get a warning about incompatible pointer types.  I
>get this message at just about every place where I use the address-of
>(&) operator.  Does Linux have trouble with the & operator, and if so,
>how does one solve this?  If there's a group especially for programming

The warning is actually one that may be ignored or casted away.  The network
interface has been designed in an OO manner where struct sockaddr is the
most basic socket type and struct sockaddr_in is the inet extension to
struct sockaddr.

Thus struct sockaddr is a super type of struct sockaddr_in and you may safely
cast the pointers.

In plain english:

if (connect (s, (struct sockaddr *) &sockaddr, sizeof (sockaddr)) < 0)
   ...

will remove the warning.

 
 
 

pointers and sockets in gcc

Post by David Washbu » Thu, 11 Aug 1994 04:57:29


I've read all the faq's I can find, as well as the gcc manual, and can't
find an answer to this question.  I hope somebody here can help me, or
point me to the right place to find the answer.

I have a multi-user game that I'm porting from SunOS Unix to Linux.  I
believe I have all the necessary include files, and the following
declaration:

struct sockaddr_in sockaddr;

When my client goes to connect, the call is like this:

if ( connect ( s, &sockaddr, sizeof(sockaddr)) < 0 )
 ...

When I compile it I get a warning about incompatible pointer types.  I
get this message at just about every place where I use the address-of
(&) operator.  Does Linux have trouble with the & operator, and if so,
how does one solve this?  If there's a group especially for programming
in Linux, I'll be happy to take my question there.  But so far, I sure
haven't been able to find the answer through the regular channels.

Thanks!

--
Dave
                        "What you spend years building may be destroyed
                        overnight.  Build anyway."  Dr. Karl Menninger

 
 
 

pointers and sockets in gcc

Post by Marc L. All » Thu, 11 Aug 1994 05:41:33



> I've read all the faq's I can find, as well as the gcc manual, and can't
> find an answer to this question.  I hope somebody here can help me, or
> point me to the right place to find the answer.
> I have a multi-user game that I'm porting from SunOS Unix to Linux.  I
> believe I have all the necessary include files, and the following
> declaration:
> struct sockaddr_in sockaddr;
> When my client goes to connect, the call is like this:
> if ( connect ( s, &sockaddr, sizeof(sockaddr)) < 0 )
>  ...
> When I compile it I get a warning about incompatible pointer types.  I
> get this message at just about every place where I use the address-of
> (&) operator.  Does Linux have trouble with the & operator, and if so,
> how does one solve this?  If there's a group especially for programming
> in Linux, I'll be happy to take my question there.  But so far, I sure
> haven't been able to find the answer through the regular channels.

The problem is that UNIX supports a number of forms for binding socket names.
Each one has a structure called 'sockaddr_xxx' where xxx is the type.
For instance sockaddr_in is for internet name bindings.

All the socket calls take an address to a generic struct 'sockaddr.'  So,
what you need to do is cast all those addresses:

        if (connect(s, (struct sockaddr *) &sockaddr, sizeof(sockaddr)) < 0)

etc.

Give that a shot!

Marc

 
 
 

1. getchar with gcc using pointers --using gcc not any other compiler

I need to make a same program to the below to getname and display it
and display certain character (certain element) .

#include <stdio.h>
/*
lesson01_creating_arrays_using_pointers.c */

main ()
{
float array_elements[50];
int no_array_elements;
int array_element_no;
input_array_elements(&no_array_elements,array_elements);
processing(no_array_elements,array_elements);
display_table(&array_element_no,array_elements);

input_array_elements(no_array_e,array_e)
//------------------------------------------------------
float *array_e;
int *no_array_e;
{
char another_element;
do {
printf ("Enter an array element :  ");
scanf("%f",&array_e[(*no_array_e)]);
printf ("More array_elements (y/n)  :  ");
scanf("\n");
scanf("%c",&another_element);
(*no_array_e)++;

processing(no_array_e,array_e)
//------------------------------------------------------
int no_array_e;
float *array_e;
{
float total=0;
int i=0;
do {
printf ("The array element no %d = %f\n",i,array_e[i]);
total=total+array_e[i];
i++;
printf ("\nThe average = %f\n",(float) total/no_array_e);

display_item(array_element_n,array_e)
//------------------------------------------------------
int *array_element_n;
float *array_e;
{
printf ("Enter an array element :  ");
scanf("%d",array_element_n);
printf ("\nThe array element is : %f \n",array_e[*array_element_n]);

2. granting commands to a user

3. Errors compiling Wingz 1.4 Add-ins (Linux 1.3.99, GCC 2.6)

4. Iomega Clik PCMCIA?

5. Matrox Mystique ands X.

6. rz fails on RH6.1, help please

7. gcc pads structures that contain pointers

8. Invoking a command as a different user

9. gcc doc pointer

10. NULL pointers and UNIX/gcc question.

11. elimination of pointer-glue / toc using gcc

12. Validating Pointers in Intel Linux 2.0.x Using gcc g++

13. gcc, ld, function pointers, and shared libraries