问题集锦(1-10)

Problem 1: when i run a program, it print out error message like”cannot open the shared library”

Ans: first, execute shell cmd: echo “/usr/local/lib” >> /etc/ld.so.conf , this will append a line to the file ld.so.conf, then execute shell cmd: /sbin/ldconfig. 

which will put your run-time linked library on the path where the linker can find it during run-time.

 

Problem 2: How to use gcc link options to compile a program?

Ans: Example: gcc -o server server.c -I/usr/local/include/mysql -L/usr/local/lib/mysql -lmysqlclient.

-I sepcify the place of your include files, -L specify the place of your lib files while -l specify the filename of a lib under your lib directory.

 

Problem 3: when i install freeradius server, I just follow the guidline step by step, but after I finish installing, I come across a big problem of “cannot find rlm_sql_mysql.so library” when i try to start the server.

Ans: the reason is that there is a little bug in the configure file. When you execute cmd of “./configure”, which is supposed to http://configure some make options and create some makefiles, but it doesn't do a fully perfect job. In the directory of src/modules/rlm_sql/drivers/rlm_sql_mysql, it creates a makefile for us, and its contents are :

 

include ../../../../../Make.inc

 

TARGET         =

SRCS           = sql_mysql.c

RLM_SQL_CFLAGS =  -I/usr/local/include/mysql $(INCLTDL)

RLM_SQL_LIBS   =

 

include ../rules.mak

 

, we can see from above, the TARGET, RLM_SQL_LIBS parameters are left unconfigured. So we need to configure the two by ourselves.

This is what the file should be like:

 

include ../../../../../Make.inc

 

TARGET         = rlm_sql_mysql

SRCS           = sql_mysql.c

RLM_SQL_CFLAGS =  -I/usr/local/include/mysql $(INCLTDL)

RLM_SQL_LIBS   = -L/usr/local/lib/mysql -lmysqlclient

 

include ../rules.mak

 

Problem 4: when accessing a file through apache httpd server in Fedora Linux, SELinux program may deny your access.

Ans: The reason is probably that httpd can not be allowed to access that file by default. The SELinux block that access request. To enable httpd to access the requested file, you need to use chcon command to change SEContext to allow this access. In Fedora 11, the httpd process runs in

1. Run: sestatus   //confirm SELinux is enabled.

2. Run: ls -Z  full path name of your file  // view the SELinux context;

3. Run: chcon -t unconfined_exec_t /usr/sbin/httpd //change the type of httpd to the type of unconfined_exec_t.

After this, you should be able to access the file through httpd server now!

 

We can also use this command “chcon -t public_content_t  full path name of your file”

 

Problem 5: How to allow a user to access the mysql server remotely?

Ans:

grant select , insert, update, delete on *(dbname).*(tablename) to user_1@"%" Identified by "password"

 

grant select , insert , update ,delete on test.iptable to fuyajun@"%" Identified by "123"

 

Problem 6: 怎样安装五笔输入法程序:fcitx-3.6(小企鹅输入法)?

Ans1. 解压fcitx-3.6.tar.tar安装包,命令为:tar -xvf fcitx-3.6.tar.tar.

     2. 进入安装目录, 分别执行如下命令:

        ./configure

        make

        make install

    3. 执行命令:ls -a /home/fuyajun

    找到隐藏文件.bashrc, 在文件结尾处加入一行:

    export XMODIFIERS="@im=fcitx"

    4. 保存退出,安装过程结束。

    5. 启动fcitx, 输入命令:whereis fcitx查看fcitx 的安装位置,默认安装位置是

    /usr/local/bin/fcitx, shell中输入该文件的全路径就可启动小企鹅五笔输入法。

    6. 如果想让输入法开机自动启动,执行如下 命令:ls -a /home/fuyajun查看主

    目录下的隐藏文件,找到.bash_profile, 打开此文件,在文件结尾处加入一行:

    /usr/local/bin/fcitx(小企鹅五笔输入法启动路径)即可。

Problem 7: 怎样获取一个网络接口的信息(IP地址,掩码,物理地址等等)?

Ans

 #define SIN_ADDR(x)    (((struct sockaddr_in *) (&(x)))->sin_addr.s_addr)

 static int get_if_info(char *name,int arg,char*buf)

{

    struct ifreq ifreq;

    int ret, sock_fd;

              unsigned char*pif;

 

    sock_fd = socket(AF_INET, SOCK_DGRAM, 0);

    if (sock_fd < 0)

        return 0;

         if(!buf)return 0;

         buf[0]=0;

    memset(&ifreq.ifr_hwaddr, 0, sizeof(struct sockaddr));

    sprintf(ifreq.ifr_name, name);

    ret = ioctl(sock_fd, arg, &ifreq);

    close(sock_fd);

    if (ret >= 0){

            switch(arg){

                case SIOCGIFADDR:

                    pif = (unsigned char*)&SIN_ADDR(ifreq.ifr_addr);

                    sprintf(buf,"%d.%d.%d.%d",pif[0],pif[1],pif[2],pif[3]);

                    break;

                case SIOCGIFNETMASK:

                    pif = (unsigned char*)&SIN_ADDR(ifreq.ifr_addr);//或者ifreq.ifr_netmask

                    sprintf(buf,"%d.%d.%d.%d",pif[0],pif[1],pif[2],pif[3]);

                    break;

                case SIOCGIFHWADDR:

                    pif = (unsigned char*)&ifreq.ifr_hwaddr.sa_data;

                    sprintf(buf,"%02X:%02X:%02X:%02X:%02X:%02X",pif[0],pif[1],pif[2],pif[3],pif[4],pif[5]);

                    break;

                case SIOCGIFFLAGS:

                    //if(ifreq.ifr_flags&IFF_RUNNING == IFF_RUNNING)return 1;

                    //else return 0;

                    //break;

                    return (int)ifreq.ifr_flags;

                case SIOCGIFMTU:

                    sprintf(buf,"%d",ifreq.ifr_mtu);

                    break;

            }

    }

    return ret;

}

相关的头文件为:

#include <sys/ioctl.h>

#include <sys/types.h>

#include <sys/socket.h>

#include <net/if.h>

#include <net/route.h>

Problem 8. Linux系统中怎样引导X Window窗口系统?

Ans: 以root的身份登录到Linux系统后,键入gedit /etc/inittab”命令,使用gedit编辑这个文件,要把登录从命令行界面改为图形化界面,需要把id:3:initdefatult:” 这一行中的数字从3必为5.修改完毕后使用[Ctrl+X]键组合来保存并退出该文件,并键入[Y]确认所做的修改,重新引导登录屏幕后就是图形化界面了。

Problem 9. How to check the validality of an email address using c programing language?

Ans: the following code can do the work:

int checkemail(char *email)

/*

 * Checks whether or not 'email' is an authentic e-mail address. checkemail()

 * will check if the domain exists, but not whether an MX record exist or a

 * responding SMTP connection established.

 *

 * Returns: 0 if 'email' is OK. != 0 if 'email' is not OK.

 *

 */

{

    char *domain;

    int i;

    int atcount = 0;//记录字符@的个数

    struct hostent *hent;

 

    if (email == NULL)

        return 1;

 

    if (!strlen(email))

        return 1;

 

    for (i = 0; email[i] != '/0'; i++)

    {

        if ((email[i] >= '0' && email[i] <= '9') || (email[i] >= 'a' && email[i] <= 'z') || (email[i] >= 'A' && email[i] <= 'Z') || (email[i] == '.') || (email[i] == '_') || (email[i] == '-') || (email[i] == '+'))

            continue;

        else if (email[i] == '@')

            atcount++;

        else

            return 1;

    }

 

    if (atcount > 1 || atcount < 1)

        return 1;

 

    if (email[0] == '@')

        return 1;

 

    if ((domain = strstr(email, "@")) == NULL)

        return 1;

 

    domain++;

 

    if (domain[0] == 0)

        return 1;

 

    if ((hent = gethostbyname(domain)) == NULL)

    {

        if (h_errno != NO_ADDRESS)

            return 1;

    }

 

    return 0;

}

 

Problem 10. How to make a program to be run as a service? 

Ans: take mysql for an example:

Step1: shell: vi /etc/rc.d/rc.local

Append a line: /user/local/httpd/bin/apachectl start

Step2: register it as a service

shell: cp /usr/local/httpd/bin/apachectl  /etc/rc.d/init.d/httpd

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值