Ted's Blog

Happy coding

检测网卡物理连接的方法

Ted posted @ 2008年8月16日 04:07 in 未分类 with tags eth0 , 3882 阅读

/* Check network adapter is up or down */
// Note: one or two adapter drivers may be not support this method
// exemple: based virtual machine

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <linux/sockios.h>
#include <linux/types.h>

const char* VERSION = "0.6.0.48 --maintain by isnowran";

struct mii_data
{
        __u16 phy_id;
        __u16 reg_num;
        __u16 val_in;
        __u16 val_out;
};

int main( int argc, char* argv[] )
{
        if( argc != 2 )
        {
                printf( "Version: %s\n", VERSION );
                printf( "Useage: argv[0] ethNO.\n" );
                return 0;
        }

        int skfd = 0;
        if( ( skfd = socket( AF_INET, SOCK_DGRAM, 0 ) ) < 0 )
        {
                perror( "socket" );
                return -1;
        }

        struct ifreq ifr;
        bzero( &ifr, sizeof( ifr ) );
        strncpy( ifr.ifr_name, argv[1], IFNAMSIZ - 1 );
        ifr.ifr_name[IFNAMSIZ - 1] = 0;
        if( ioctl( skfd, SIOCGMIIPHY, &ifr ) < 0 )
        {
                perror( "ioctl" );
                return -1;
        }

        struct mii_data* mii = NULL;
        mii = (struct mii_data*)&ifr.ifr_data;
        mii->reg_num = 0x01;
        if( ioctl( skfd, SIOCGMIIREG, &ifr ) < 0 )
        {
                perror( "ioctl2" );
                return -1;
        }

        if( mii->val_out & 0x0004 )
                printf( "Linkup\n" );
        else
                printf( "Linkdown\n" );

        close( skfd );
        return 0;
}

Avatar_small
Earl Tirado 说:
2020年2月24日 18:53

All the changes are welcomed for the depiction for the theorists for the field. All the changes of the essayshark reviews are planned for the outcomes for the individuals. The change is surd for the room. Plan is fit for the students. The aspect is coined for the mode of the discussion for the ray and way of the hopeful mans.

Avatar_small
Digital_Work 说:
2020年10月31日 04:04

Best work you have done, this online website is cool with great facts and looks. I have stopped at this blog after viewing the excellent content. I will be back for more qualitative work. hasta yatağı kiralama

Avatar_small
Digital_Work 说:
2020年10月31日 04:17

Best work you have done, this online website is cool with great facts and looks. I have stopped at this blog after viewing the excellent content. I will be back for more qualitative work. hasta karyolası

Avatar_small
Digital_Work 说:
2020年10月31日 04:34

Wonderful blog! Do you have any tips and hints for aspiring writers? Because I’m going to start my website soon, but I’m a little lost on everything. Many thanks! thy uçak bileti

Avatar_small
Digital_Work 说:
2020年10月31日 04:41

Believe it or not, it is the type of information I’ve long been trying to find. It matches to my requirements a lot. Thank you for writing this information. bodrum rodos feribot

Avatar_small
Digital_Work 说:
2020年10月31日 05:05

Thanks a lot for sharing this excellent info! I am looking forward to seeing more posts by you as soon as possible! I have judged that you do not compromise on quality. hasta yatağı kiralama

Avatar_small
Digital_Work 说:
2020年10月31日 05:12

Thanks for your insight for your fantastic posting. I’m exhilarated I have taken the time to see this. It is not enough; I will visit your site every day. Plastic Surgery in Turkey

Avatar_small
Digital_Work 说:
2020年10月31日 05:18

Thanks a lot for sharing this excellent info! I am looking forward to seeing more posts by you as soon as possible! I have judged that you do not compromise on quality. dış cephe cam temizliği

Avatar_small
Digital_Work 说:
2020年10月31日 05:25

Excellent post. I was reviewing this blog continuously, and I am impressed! Extremely helpful information especially this page. Thank you and good luck. pubg mobil hile satın al

Avatar_small
Digital_Work 说:
2020年10月31日 05:34

It is an excellent blog, I have ever seen. I found all the material on this blog utmost unique and well written. And, I have decided to visit it again and again. elektronik sigara kapıda ödeme

Avatar_small
Digital_Work 说:
2020年10月31日 05:42

It is an excellent blog, I have ever seen. I found all the material on this blog utmost unique and well written. And, I have decided to visit it again and again. hasta yatakları

Avatar_small
Digital_Work 说:
2020年11月14日 17:33

Wonderful blog! Do you have any tips and hints for aspiring writers? Because I’m going to start my website soon, but I’m a little lost on everything. Many thanks! https://apnews.com/press-release/ts-newswire/technology-business-cryptocurrency-financial-technology-south-africa-ee038bb5ba004fc99868d5db1e337b1c

Avatar_small
Digital_Work 说:
2020年11月14日 17:49

thank you for your interesting infomation. bitcoin revolution south africa patrice motsepe

Avatar_small
Digital_Work 说:
2020年11月14日 17:55

Great post but I was wondering if you could write a little more on this subject? I’d be very thankful if you could elaborate a little bit further. Thanks in advance! bitcoin revolution patrice motsepe

Avatar_small
Digital_Work 说:
2020年11月14日 18:09

I read your blog frequently, and I just thought I’d say keep up the fantastic work! It is one of the most outstanding blogs in my opinion. bitcoin revolution south africa patrice motsepe

Avatar_small
Digital_Work 说:
2020年11月14日 18:14

What a thrilling post, you have pointed out some excellent points, I as well believe this is a superb website. I have planned to visit it again and again. http://www.ladieswholunch.co.za/

Avatar_small
LEGEND SEO 说:
2021年1月04日 18:55

thanks for this usefull article, waiting for this article like this again. 123freemovies

Avatar_small
UMAIR 说:
2021年1月05日 16:46

JAC 10th Model Question Paper 2021: Are you searching class 10th model paper Jharkhand Board? If yes, then get latest updates about a JAC 10 model Jharkhand 10th Question Paper 2021 paper from official website i.e jac.jharkhand.gov.in/jac. Download Jharkhand Board 10th Question Paper available for Hindi, English, Mathematics, Science, S.S.T, Skt in both medium Hindi or English. Take board 10th question paper 2021-21 and understand the level of exam pattern important topic. Solve each question carefully because sometimes question it repeat.

Avatar_small
UMAIR 说:
2021年1月07日 15:26

Everyone in this era is looking to earn profits and revenue. Keeping this in mind http://www.appreviewcentral.net/2020/11/02/how-to-boost-your-workflow-with-e-signature-solutions/ has mentioned the ways to promote the businesses on different websites. This gives the advantage of free advice.

Avatar_small
LEGEND SEO 说:
2021年1月09日 22:11

Hi there! Nice stuff, do keep me posted when you post again something like this! 메이저사이트

Avatar_small
Legend Seo 说:
2021年1月12日 19:32

This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. casino online pl

Avatar_small
UMAIR 说:
2021年1月14日 16:12

major problem arrives as people are unable to access the website from their mobile. But now asfr.altomerge.com mentions in their company they say that it is easily accessible from mobile as well. This eases individuals and also solution is both trustworthy and practical

Avatar_small
전설 서구 说:
2021年1月14日 18:26

I was surfing the Internet for information and came across your blog. I am impressed by the information you have on this blog. It shows how well you understand this subject. best canadian online casino

Avatar_small
먹튀검증 说:
2021年1月23日 06:44

Remarkable article, it is particularly useful! I quietly began in this, and I'm becoming more acquainted with it better! Delights, keep doing more and extra impressive!

Avatar_small
UMAIR 说:
2021年1月27日 19:29

The Carpenter Library aspires to be the intellectual center of its community, to foster innovations thatunf library database lead to the discovery of knowledge, and to further 2021. The Carpenter Library aspires to be the intellectual center of its community, to foster innovations that lead to the discovery of knowledge, and to further 2021

Avatar_small
리니지프리서버 说:
2021年1月30日 19:35

Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!Thanks

Avatar_small
JHON 说:
2021年1月31日 01:09

You understand your projects stand out of the crowd. There is something unique about them. It seems to me all of them are brilliant. fundamentals of heat and mass transfer 8th edition

Avatar_small
먹튀폴리스 说:
2021年2月06日 02:06

That appears to be excellent however i am still not too sure that I like it. At any rate will look far more into it and decide personally!

Avatar_small
토토사이트 说:
2021年3月11日 19:22

I am continually amazed by the amount of information available on this subject. What you presented was well researched and well worded in order to get your stand on this across to all your readers.

Avatar_small
먹튀검증 说:
2021年3月21日 19:13

It is my first visit to your blog, and I am very impressed with the articles that you serve. Give adequate knowledge for me. Thank you for sharing useful material. I will be back for the more great post.

Avatar_small
nevenmaguireblog.com 说:
2021年4月12日 03:00

Wow, cool post. I’d like to write like this too – taking time and real hard work to make a great article… but I put things off too much and never seem to get started. Thanks though.

Avatar_small
wm casino 说:
2021年4月18日 03:46

Best casino site # 1 in Asia, quality guaranteed, WM casino, baccarat betting, extreme, football betting, lottery, slots, roulette, full All camps here, only one place No boring bets, no wagering money, only here

Avatar_small
dark web/deep web/d 说:
2022年8月04日 18:55

The JavaScript that hides these links is part of the programming that most web browsers are programmed to run. However, some advanced JavaScript hackers have discovered ways to bypass JavaScript codes and access the Dark Web.  dark web links

Avatar_small
dark web/deep web/d 说:
2022年8月04日 19:40

Some sites allow you to browse their Dark Web links for free. While it is possible to find many of these websites online, they are generally not worth the time or effort it takes to investigate them.   deep web

Avatar_small
dark web/deep web/d 说:
2022年8月04日 19:55

While using search engines to discover Bangla links can be effective, it is recommended that you also expose yourself to the world of the Dark Web in order to gain access to the many interesting, informative, and entertaining web sites that can help you stay ahead of the trends on the Internet.  dark web links

Avatar_small
dark web/deep web/d 说:
2022年8月04日 20:17

All this activity is a huge boon to the hackers and scammers out there who wish to get your personal information. The darker the links to the website, the more valuable the information is to them.   dark web sites

Avatar_small
dark web/deep web/d 说:
2022年8月04日 20:32

As with anything else on the internet, people will always be willing to try new ways to get rich. So why not try your hand at making a bit of extra money? There is a lot of room here to make a living, and the benefits of Dark Web links are plenty.  dark web

Avatar_small
dark web/deep web/d 说:
2022年8月04日 20:48

Most of the other things that he teaches you in his real affiliate marketing success stories program are extremely valuable. They include finding good advertising sources, choosing the best products to promote, writing good sales copy, and more.   work from home jobs

Avatar_small
dark web/deep web/d 说:
2022年8月04日 21:05

If you have your own product, be sure to incorporate a weight-loss component into it. It can be as simple as a free eBook or a complete program like Head Starts.   affiliate marketing success

Avatar_small
jsimitseo 说:
2024年1月30日 19:24

The best article I ran over various years, compose something about it on this page.  concierge doctor naples


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter