Program to find IP address

C program to find IP address using ioctl() system call.

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#include<errno.h>
#include<arpa/inet.h>
#include<netinet/in.h>
#include<sys/socket.h>
#include<sys/ioctl.h>
#include<sys/types.h>
#include<net/if.h>

/**
+++++++++++++++++++++++++++++++
Program:- Find IP address using ioctl
+++++++++++++++++++++++++++++++
Author:- Surendra S.Patil
+++++++++++++++++++++++++++++++
I/P:- interface name ex:- “eth0 ”
+++++++++++++++++++++++++++++++
O/P:- Ip address (192.168.2.2)
+++++++++++++++++++++++++++++++
*/

int main()
{
int sock_fd;
struct ifreq interface;

/* create socket and get socket descriptor */
sock_fd = socket(AF_INET,SOCK_DGRAM,0);

if (-1 == sock_fd) {
fprintf(stderr,”errno:- %d :- %s”,errno,strerror(errno));
exit(EXIT_FAILURE);
}

/* copy the interface name */
strcpy(interface.ifr_name,”eth0″);

if(-1 == ioctl(sock_fd,SIOCGIFADDR,&interface)) {
fprintf(stderr,”errno:- %d :- %s”,errno,strerror(errno));
exit(EXIT_FAILURE);
}

printf(“Interface = %s\n IP Address = %s\n”,interface.ifr_name,
inet_ntoa(((struct sockaddr_in *)&interface.ifr_addr)->sin_addr));

close(sock_fd);
exit(EXIT_SUCCESS);

}

Run the program:-

run ipaddr.c

Constant Pointer and Pointer to constants

Constant Pointer:-

It is type of pointer whose address cannot be modified after first time initialization.
Ex:-
 #include<stdio.h>
   int main()
   {
       int var = 10, var2 = 20;
       int *const ptr = &var;
       ptr = &var2;                /* error cant change read only ptr is constant*/
       *ptr = 30;                  /* value can be changed */
       printf(“ptr  = %d\n”,*ptr);
      return 0;
  }
In this program ptr is constant which cannot hold the other addresses but value can be modified.
Pointer to a constant:-
It is type of pointer in which the data  pointed cannot be modified.
Ex:-
#include<stdio.h>
     int main()
   {
       int var = 10, var2 = 20;
       const int* ptr = &var;
       ptr = &var2;                /* can change the address */
       *ptr = 30;                  /* error data is constant  */
       printf(“ptr  = %d\n”,*ptr);
      return 0;
  }
In this program ptr points to constant data which cannot be modified,but address can be modified.
Constant pointer to a constant:-
This is combination of above to here data and address are constants.
Ex:-
#include<stdio.h>
   int main()
 {
     int var = 10, var2 = 20;
     const int* const ptr = &var;
      ptr = &var2;                /* error address is constant */
      *ptr = 30;                  /* error data is constant  */
      printf(“ptr  = %d\n”,*ptr);
      return 0;
 }
Easy way to remember:-
const int * ptr :- if * comes after const then data is constant.
int * const  ptr :-  if * comes before const then address is constant.
cons int * const ptr :- address and data both are constant.

 

7 Effective Ways of job search for freshers

 Lot of fresher’s face problems in   job Hunting, Hunting a good job is also a skill, which needs little out of box thinking. Here are few tips from my personal experience which may help to kick start your dream job hunt.
 

1)      Create  simple CV:-

Your CV should focus on the Academic details, skills and projects you have done.

2)      Post your CV on popular job sites :-

Build a simple and short CV and post it on all popular job sites like

3)      Social networking :-

This is the era of social networking; job seekers must actively involve in networking.  Create profiles in social networking sites and join job search groups and keep checking the posts and do post there when you have some job updates.

4)      Prepare Well:- 

Do some research on company and the job profile, prepare on that bases.  For IT Company I would suggest to focus on:-

  • Quantitative Aptitude.
  • Programming language basics (C, C++, Java, .Net etc) any one, you should be able to write programs in it.
  • Data Structures and Database Management Concepts.
  • Software Development Life Cycle and Basic Networking Concepts.
  • Be thorough with your academic project.
  •  Google the company test papers and prepare based on that.
  • Prepare well for self introduction.

5)      Don’t Think Just Attend:- 

Just keep on attending all the job requirements it may be consultancy or job fair, you will learn something from it and you will get opportunity to build your network by meeting new people who may help you in hunting job.

6)      Dress neatly and be on time:-

Dress yourself neatly in formals and be on time at the venue it depicts your interest.

7)      Don’t Give up:- 

Don’t give up till you hit your dream job, job searching is not that much easy, keep going whatever it may be, and you will get your dream job one day. Just remember this quote

“Something Big is Waiting for me “

All the Best 🙂 🙂 🙂